home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / tcega.arc / GPWSPACE.C < prev    next >
Text File  |  1986-03-06  |  3KB  |  183 lines

  1.  
  2. #include <stdio.h>
  3. #include <dos.h>
  4. #include <mcega.h>
  5.  
  6.   WORKSPACE *gdwscore;
  7.   WORKSPACE *gdwsswap;
  8.   WORKSPACE *gdwschr1;
  9.   WORKSPACE *gdwschr2;
  10.  
  11.   char *gdwspath;
  12.  
  13. void gpinitws(path)
  14.   char *path;
  15. {
  16.   static WORKSPACE charset1 =
  17.     {
  18.     1,0xC230,0,8,3584,0,0,8,14,0
  19.     };
  20.  
  21.   static WORKSPACE charset2 =
  22.     {
  23.     1,0xC316,0,8,2048,0,0,8,8,0
  24.     };
  25.  
  26.   gdwscore = NULL;
  27.   gdwsswap = NULL;
  28.  
  29.   gdwschr1 = &charset1;
  30.   gdwschr2 = &charset2;
  31.  
  32.   gdwspath = path;
  33.  
  34. }
  35.  
  36. void gptermws()
  37. {
  38.   extern void gpdelws();
  39.  
  40.   register WORKSPACE *j;
  41.  
  42.   j = gdwscore;
  43.   while (j != NULL)
  44.     {
  45.     gpdelws(j);
  46.     j = (WORKSPACE *)j->next;
  47.     }
  48.  
  49.   j = gdwsswap;
  50.   while (j != NULL)
  51.     {
  52.     gpdelws(j);
  53.     j = (WORKSPACE *)j->next;
  54.     }
  55. }
  56.  
  57. WORKSPACE *gpgenws(width,height,bits)
  58.   int width,height,bits;
  59. {
  60.   extern WORKSPACE *calloc();
  61.   extern void gpdelws();
  62.  
  63.   register i;
  64.   register WORKSPACE *j;
  65.  
  66.   if ((j = calloc(sizeof(WORKSPACE),1)) == NULL)
  67.     {
  68.     gpterm();
  69.     perror("GPGENWS: Out of local memory!\n");
  70.     exit(1);
  71.     }
  72.  
  73.   if (bits <= 8)
  74.     {
  75.     i = 8/bits;
  76.     i = ((width + i - 1) / i * height + 15) / 16;
  77.     }
  78.   else
  79.     {
  80.     i = width * height / 8;
  81.     };
  82.  
  83.   j->bits    = bits;
  84.   j->segment = gpgetmem(i);
  85.   j->para    = i;
  86.   j->width   = width;
  87.   j->height  = height;
  88.   j->x       = 0;
  89.   j->y       = 0;
  90.   j->w       = width;
  91.   j->h       = height;
  92.   j->next    = (char *)gdwscore;
  93.  
  94.   gdwscore = j;
  95.  
  96. }
  97.  
  98. void gpdelws(ws)
  99.   WORKSPACE *ws;
  100. {
  101.   union  REGS  inregs, otregs;
  102.   struct SREGS segregs;
  103.  
  104.   char buf[64];
  105.  
  106.   register WORKSPACE *i;
  107.   register WORKSPACE *j;
  108.  
  109.   j = gdwscore;
  110.   while (j != NULL)
  111.     {
  112.     if (ws == j)
  113.       {
  114.       inregs.h.ah = 0x49;
  115.       segregs.es  = j->segment;
  116.       intdosx(&inregs,&otregs,&segregs);
  117.       if (j == gdwscore)
  118.         {
  119.         gdwscore = (WORKSPACE *)j->next;
  120.         }
  121.       else
  122.         {
  123.         i->next = j->next;
  124.         };
  125.       free(j);
  126.       return;
  127.       }
  128.     i = j;
  129.     j = (WORKSPACE *)j->next;
  130.     }
  131.  
  132.   j = gdwsswap;
  133.   while (j != NULL)
  134.     {
  135.     if (ws == j)
  136.       {
  137.       sprintf(buf,"%s\WS_%u.$$$",gdwspath,j);
  138.       unlink(buf);
  139.  
  140.       if (j == gdwsswap)
  141.         {
  142.         gdwsswap = (WORKSPACE *)j->next;
  143.         }
  144.       else
  145.         {
  146.         i->next = j->next;
  147.         };
  148.       free(j);
  149.       return;
  150.       }
  151.     i = j;
  152.     j = (WORKSPACE *)j->next;
  153.     }
  154.  
  155. }
  156.  
  157. int gpgetmem(para)
  158.   unsigned para;
  159. {
  160.   union  REGS  inregs, otregs;
  161.   struct SREGS segregs;
  162.  
  163.   char buf[64];
  164.  
  165.   register i;
  166.   register WORKSPACE *j;
  167.  
  168.   inregs.h.ah = 0x48;
  169.   inregs.x.bx = para;
  170.  
  171.   intdosx(&inregs,&otregs,&segregs);
  172.  
  173.   if (otregs.x.cflag == 0)
  174.     {
  175.     return(otregs.x.ax);
  176.     };
  177.  
  178.   gpterm();
  179.   perror("GPGETMEM: Out of system memory!\n");
  180.   exit(1);
  181.  
  182. }
  183.